# 删除所有变量
rm(list=ls())
gc()

# 加载必要的packages
library(tidyverse)

# 设定存储路径
setwd("D:/studyR")

# 输入names.csv
name<-read.csv("name.csv",stringsAsFactors = F, header=T)
View(name)

colnames(name)<-c("name","gender","edu","native","age","viewpoint")

# 了解数据
#### 1. 有多少个样本
dim(name)
str(name)
summary(name)

#### 2. 改变观测值的类别
name$gender<-factor(name$gender)
name$edu<-ordered(name$edu,levels=c("中学","大学","研究生"))
name$native<-factor(name$native)
name$viewpoint<-factor(name$viewpoint)

#### 3. 有图有真相
plot(name$gender)
barplot(table(name$gender))
hist(name$age,freq=T)



young<-subset(name,age<=25)
middle<-subset(name,age>25&age<=59)

